home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright 1991, 1992, 1993, 1994, Silicon Graphics, Inc.
- * All Rights Reserved.
- *
- * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
- * the contents of this file may not be disclosed to third parties, copied or
- * duplicated in any form, in whole or in part, without the prior written
- * permission of Silicon Graphics, Inc.
- *
- * RESTRICTED RIGHTS LEGEND:
- * Use, duplication or disclosure by the Government is subject to restrictions
- * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
- * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
- * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
- * rights reserved under the Copyright Laws of the United States.
- */
- /*
- * iclose and iflush -
- *
- * Paul Haeberli - 1984
- *
- */
- #include <stdio.h>
- #include <stdlib.h>
- #include "image.h"
-
- int
- iclose(image)
- register IMAGE *image;
- {
- long tablesize;
-
- iflush(image);
- img_optseek(image, 0);
- if (image->flags&_IOWRT) {
- if(image->dorev)
- cvtimage(image);
- if (img_write(image,image,sizeof(IMAGE)) != sizeof(IMAGE)) {
- i_errhdlr("iclose: error on write of image header\n");
- return EOF;
- }
- if(image->dorev)
- cvtimage(image);
- if(ISRLE(image->type)) {
- img_optseek(image, 512L);
- tablesize = image->ysize*image->zsize*sizeof(long);
- if(image->dorev)
- cvtlongs(image->rowstart,tablesize);
- if (img_write(image,image->rowstart,tablesize) != tablesize) {
- i_errhdlr("iclose: error on write of rowstart\n");
- return EOF;
- }
- if(image->dorev)
- cvtlongs(image->rowsize,tablesize);
- if (img_write(image,image->rowsize,tablesize) != tablesize) {
- i_errhdlr("iclose: error on write of rowsize\n");
- return EOF;
- }
- }
- }
- if(image->base) {
- free(image->base);
- image->base = 0;
- }
- if(image->tmpbuf) {
- free(image->tmpbuf);
- image->tmpbuf = 0;
- }
- if(ISRLE(image->type)) {
- free(image->rowstart);
- image->rowstart = 0;
- free(image->rowsize);
- image->rowsize = 0;
- }
- return(close(image->file));
- }
-
- iflush(image)
- register IMAGE *image;
- {
- unsigned short *base;
-
- if ( (image->flags&_IOWRT)
- && (base=image->base)!=NULL && (image->ptr-base)>0) {
- if (putrow(image, base, image->y,image->z)!=image->xsize) {
- image->flags |= _IOERR;
- return(EOF);
- }
- }
- }
-